<template>
<h2 algin="center">管理员增加借款</h2>
<table class="table table-bordered">
    <tr>
        <td>借款款项名称</td>
        <td>
            <input type="text" v-model="state.B_Name" />
        </td>
    </tr>
    <tr>
        <td>借款最高金额</td>
        <td><input type="text" v-model="state.B_Money" /></td>
    </tr>
    <tr>
        <td>借款最高年限</td>
        <td><input type="text" v-model="state.B_Year" /></td>
    </tr>
    <tr>
        <td>利息</td>
        <td>
                  <select v-model="state.I_Id">
                    <option value="0">--请选择--</option>
                    <option :value="item.I_Id" v-for="item in list">{{ item.I_Year}}年{{item.I_Interest}}%</option>
                  </select>
                </td>
    </tr>
    <tr>
        <td>借款款项简介</td>
        <td><input type="textarea" v-model="state.B_Info" /></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="button" value="添加" @click="add" /></td>
    </tr>
    
</table>
</template>

<script setup lang="ts">
import{reactive,ref,toRefs,onMounted} from 'vue'
import { useRouter } from 'vue-router'
import axios from 'axios'
let router=useRouter()
let data:any=reactive({
    list:[],
    state:{
        B_Name:'',
        B_Year:'',
        B_Money:'',
        I_Id:'0',
        B_Info:'',
    }
})
let {state,list}=toRefs(data)

const add=()=>{
    axios({
        url:"/api/Borrow/PostBorrowAdd",
        method:'post',
        data:state.value
    })
    .then(res=>{
        console.log(res.data.data);
        if(res.data.data>0){
            alert("添加成功哈哈哈");
            router.push("/main/borrowList")
        }
        else{
            alert("添加失败");
        }
    })
    .catch(err=>{
        console.log(err);
    })
   
}
onMounted(()=>{
    seltype();
})
const seltype=()=>{
    axios({
        url:"/api/Borrow/SelInterest",
        method:'get',
    })
    .then(res=>{
        console.log(res.data.data);
        list.value=res.data.data;
    })
    .catch(err=>{
        console.log(err);   
    })
}




</script>



<style scoped>

</style>